package logic

import (
	"context"
	"mall/mallrpc/mallrpc"

	"mall/api/internal/svc"
	"mall/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdatePasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdatePasswordLogic {
	return &UserUpdatePasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserUpdatePasswordLogic) UserUpdatePassword(req *types.UserUpdatePasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	password, err := l.svcCtx.MallRpc.UserUpdatePassword(l.ctx, &mallrpc.UserUpdatePasswordRequest{
		Tel:       req.Tel,
		Password:  req.Password,
		Password1: req.Password1,
		Code:      req.Code,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "修改成功",
		Code:    "200",
		Data:    password,
	}, nil
}
